package city.spring.modules.material.service.impl;

import city.spring.modules.material.entity.MaterialBreakageDeliveryMaterialEntity;
import city.spring.modules.material.repository.MaterialBreakageDeliveryMaterialRepository;
import city.spring.modules.material.service.MaterialBreakageDeliveryMaterialService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Service：报损出库关联物资表
 *
 * @author 谢金婷
 * @date 2021-01-20 10:53:12
 */
@CacheConfig(cacheNames = {MaterialBreakageDeliveryMaterialServiceImpl.CACHE_NAME})
@Transactional(rollbackFor = Exception.class)
@Service
public class MaterialBreakageDeliveryMaterialServiceImpl extends ServiceImpl<MaterialBreakageDeliveryMaterialRepository, MaterialBreakageDeliveryMaterialEntity> implements MaterialBreakageDeliveryMaterialService {

    @Override
    public void saveMaterialBreakageDeliveryMaterial(MaterialBreakageDeliveryMaterialEntity entity) {
        if (!save(entity)) {
            throw new RuntimeException("保存信息失败");
        }
    }

    @Override
    public void updateMaterialBreakageDeliveryMaterial(MaterialBreakageDeliveryMaterialEntity entity) {
        // 使用 updateById(entity); 修改数据时，将会修改 entity 对象中所有非null数据，如果某个字段为null，将会忽略该字段的修改
        if (!updateById(entity)) {
            throw new RuntimeException("修改信息失败");
        }
    }

    @Override
    public void deleteMaterialBreakageDeliveryMaterial(String primaryKey) {
        removeById(primaryKey);
    }

    @Override
    public void deleteMaterialBreakageDeliveryMaterial(List<String> primaryKeys) {
        removeByIds(primaryKeys);
    }
}